<?php
Database($_SESSION['cid']);
class InformationAction extends Action{

    public function index(){
        $rs   = pageing('information',7,'',$_GET['seach'],'information_id desc','time_insert > time_delete','information_title','',"DB_MEETING");
        $channel = M('information_channel' , '' , 'DB_MEETING') ->select();
        
        foreach ($channel as $key => $value) {
            $d[$value['channel_id']] = $value; 
        }
        foreach ($rs['data'] as $k => $v) {
            $rs['data'][$k]['channel_name'] = $d[$v['information_channel']]['channel_name'];
        }

        $this->assign("rs",$rs);
        $this->display();
    }
    public function channel_index()
    {
        $channel = pageing('information_channel',5,'',$_GET['seach'],'channel_id desc','time_insert > time_delete','channel_name','channel_index',"DB_MEETING");
        $this->assign("channel",$channel);
       
        $this ->display();
    }
    
    public function del()
    {
        $rs = D('Information')->to_del($_GET);
        if($rs){
            $this->success('删除成功',__URL__.'/index');
        }
        else
            $this->error('删除失败',__URL__.'/index');
    }
    public function del_channel()
    {
        $rs = D('Information')->to_del_channel($_GET);
        if($rs){
            $this->success('删除成功',__URL__.'/index');
        }
        else
            $this->error('删除失败',__URL__.'/index');
    }

    public function to_update()
    {
        $rs =M('information' , '' , 'DB_MEETING')->where('information_id='.$_GET['information_id'])->find();
        
        $r = M('information_channel' , '' , 'DB_MEETING')->select();
        $this ->assign('rs' , $rs);
        $this ->assign("r" , $r);
        $this ->display();
    }

    public function channel_to_update()
    {
        $rs =M('information_channel' , '' , 'DB_MEETING')->where('channel_id='.$_GET['channel_id'] )->find();
        $this ->assign('rs' , $rs);
        $this ->display();
    }
    public function channel_update()
    {   
        $rs = M('information_channel' ,'' ,'DB_MEETING')->where('channel_id='.$_POST['channel_id'])->save($_POST);
        if($rs)
            $this->success('修改成功',__URL__.'/channel_index');
        else
            $this->error('修改失败');
    }
    public function upt()
    {
    	$rs = D('Information') ->update_information($_POST);
        if($rs)
            $this->success('修改成功',__URL__.'/index');
        else
            $this->error('修改失败');
    }

    public function to_add()
    {
        $rs = M('information_channel' , '' , 'DB_MEETING')-> where("time_insert>time_delete")->select();
        $category = M('information_suggest' , '' , 'DB_MEETING') ->select();
        $this ->assign('rs' , $rs);
        $this ->assign('category' , $category);
        $this ->display();
    }

    public function to_add_information()
    {
        $rs = D('Information') ->add_information($_POST);
        if($rs)
            $this->success('添加信息成功',__APP__."/Information/index");
        else
            $this ->error('添加信息失败',__APP__."/Information/to_add");
    }

    public function channel_to_add()
    {   
        $this ->display();
        
    }
    public function add_channel()
    {
        $rs = D('Information') ->add_information_channel($_POST);
        if($rs)
            $this->success('添加信息成功',__APP__."/Information/channel_index");
        else
            $this ->error('添加信息失败',__APP__."/Information/channel_to_add");
    }
}